package com.smh.aiagent.tools;

import com.smh.aiagent.model.pojo.FileInfo;
import com.smh.aiagent.template.MinioTemplate;
import lombok.AllArgsConstructor;
import org.springframework.ai.chat.model.ToolContext;
import org.springframework.ai.tool.annotation.Tool;
import org.springframework.ai.tool.annotation.ToolParam;

/**
 * @author shiminghui
 * @date 2025/6/5 22:19
 * @description: 文件上传工具类
 */
@AllArgsConstructor
public class FileUploadTool {

    private final MinioTemplate minioTemplate;

    @Tool(description = "Uploads a file to the server and generates a publicly accessible URL. " +
            "When the user says 'send it to me' or similar phrases, this tool should be used to upload the file to storage " +
            "and return a link that allows the user to access the file.")
    public String uploadFile(@ToolParam(description = "Path of the file to upload") String filePath,
                             ToolContext toolContext) {
        // 获取文件
        FileInfo fileInfo = minioTemplate.uploadFile(filePath);
        if (fileInfo == null) {
            return "Failed to upload file";
        }
        return "The file has been successfully uploaded. You can access it using the following link: " + fileInfo.getUrl() + ". Feel free to share or download it!";

    }

}
